import django
import sys
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

try:
    from public import setting_overrides
    settings_path = 'public.setting_overrides'
except ImportError:
    settings_path = 'public.settings'

os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_path)
django.setup()


from libs.wx.xcx import get_access_token
from urllib.parse import quote_plus
import requests

# 生成永久活动二维码

api = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=' + get_access_token()
url = '/app/activity/?page=220830'
params = {
    'path': f'pages/home/banner/index?scene=' + quote_plus(url),
    'width': 750,

}
res = requests.post(api, json=params)
with open('test.jpg', 'wb') as f:
    f.write(res.content)

